//zengchuixin 2008-09-05
//markUiElement
function markUiElement(windowType){
	markEditer(windowType);
	//markSelect();
	//markValidateTip();
}

/**
 * @param windowType {渲染界面风格} 
 */
function markEditer(windowType){
	try{
	    jQuery(document).find("div").each(function(i) {
	    	if(this.id.indexOf('Tree') != -1){
	    		jQuery("#"+this.id).addClass("treeHeight");l
	    	}
	    	var content = jQuery("#"+this.id).html();
	    	var Repl = "";
	    	var endDiv = document.getElementById(this.id+'end');
	    	//改变主页面tab标题
	    	if(this.id.indexOf('ModelName') != -1  && i==0 ){
	    		jQuery("#"+this.id).html('');
	    		var eleHead = parent.document.getElementById('tabPl').firstChild;
	    		if(eleHead != null && eleHead != undefined){
					tbl_title = eleHead.innerText;
					if(tbl_title != content){
						eleHead.innerHTML = eleHead.innerHTML.replace(tbl_title ,content);
					}
				}
			}
			//查询条件、查询内容
	    	if(this.id.indexOf('Title') != -1 && endDiv == null ){
	    		jQuery("#"+this.id).css("width","100%");
		    	Repl += "    <DIV id='dlTitle' class='x-panel-tl' style='width:100%'>";
				Repl += "		<DIV class='x-panel-tr' style='width:100%'>";
				Repl += "			<DIV class='x-panel-tc' style='width:100%'>";
				Repl += "				<DIV class='x-panel-header x-unselectable' style='width:100%;white-space:nowrap;text-align:center;MozUserSelect: none; KhtmlUserSelect: none' unselectable='on'>";
				//是否出现收缩按钮
				var inner = this.id.substr(0,this.id.length - 5)+'Inner';
				var searchTool = jQuery('#'+inner);
				Repl += "<table width='100%' border='0'><tr><td width='22px'>";
				//if((searchTool != null)&&(searchTool.attr("search") == 'true')){
					//Repl += "					<SPAN class='x-panel-header-text'>查询</SPAN>";
				//}else{
					//Repl += "					<SPAN class='win-header-text'>" + content + "</SPAN>";
					if((searchTool != null)&&(searchTool.attr("search") == 'true')){
							Repl += "<DIV id='searchTool' class='searchToggle' onclick=closeSearch('"+inner+"');></DIV>";
		    		}else{
		    			Repl += "&nbsp;";
		    		}
				//}
				Repl += "</td><td class='win-header-text' nowrap>";
					Repl += content ;
				Repl += "</td></tr></table>";
				Repl += "				</DIV>";
				Repl += "			</DIV>";
				Repl += "		</DIV>";
				Repl += "	</DIV>";
	    	}else if(this.id.indexOf('Inner') != -1 && endDiv == null ){
			//	Repl += "	<DIV class='x-panel-bwrap' id='"+this.id+"Search' style='width:100%;height:100%'>";
			//	Repl += "		<DIV class='x-panel-ml' style='width:100%;height:100%'>";
			//	Repl += "			<DIV class='x-panel-mr' style='width:100%;height:100%'>";
			//	Repl += "				<DIV class='x-panel-mc' style='height:100%'>";
			//	Repl += "					<DIV class='x-panel-body'>" + content + "</DIV>";
			//	Repl += "				</DIV>";
			//	Repl += "			</DIV>";
			//	Repl += "		</DIV>";
				//Repl += "		<DIV class='x-panel-bl x-panel-nofooter' style='width:100%'>";
				//Repl += "			<DIV class='x-panel-br' style='width:100%'>";
				//Repl += "				<DIV class='x-panel-bc' style='width:100%'></DIV>";
				//Repl += "			</DIV>";
				//Repl += "		</DIV>";
			//	Repl += "	</DIV>";
			//	jQuery("#"+this.id).css("width","100%");
	    		//jQuery("#"+this.id).css("height","80%");
	    	}
	    	if(Repl != ""){
	    		Repl += "<div id='"+this.id+"end'></div>";
	    		var tableS = "<table width=100% style='border:1px solid red;' id='sehtable'><tr><td width=100%>";
	    		var tableE = "</td></tr></table>"
				jQuery("#"+this.id).html(Repl);
				try{
				//alert(document.body.scrollWidth);
				//jQuery("#sehtable").css("width",document.body.scrollWidth);
				}catch(e){alert(e);}
				Repl= null;
	    	}
			
	    	//jQuery("#"+this.id).attr("class","x-panel-header x-unselectable");
	    	//jQuery("#"+this.id).css("width","102%");
	    });

	    if(editerValidate()){
			editerValidate();
		}else if(searchValidate()){
			searchValidate();
		}
	}catch(e){
		//alert(e);
	}
}

/**
 * 查询条件区域收缩
 * @param searchId {收缩按钮Id} 
 */
function closeSearch(searchId){
	var divSearch = jQuery("#"+searchId);
	if(divSearch.css("display")== "block"){
		jQuery('#searchTool').removeClass('searchToggle');
		jQuery('#searchTool').addClass('searchClose');
		divSearch.css("display","none");
	}else{
		jQuery('#searchTool').removeClass('searchClose');
		jQuery('#searchTool').addClass('searchToggle');
		divSearch.css("display","block");
	}
	jQuery('body').css('overflow-y','hidden');
	for (var ecId in ECSideList ){
		ECSideUtil.setECSideHeight(ECSideList[ecId].id);
	}
	jQuery('body').css('overflow-y','auto');
}

function addReturnPx(pram1 , pram2){
	var p1 = pram1.replace("px","");
	var p2 = pram2.replace("px","");
	return (p1 + p2) + "px";
}

function subtReturnPx(pram1 , pram2){
	var p1 = parm1.replace("px","");
	var p2 = pram2.replace("px","");
	return (p1 - p2) + "px";
}



/**
 * 弹出窗体
 * @param url {弹出窗体装载URL} 
 * @param wWidth {弹出窗体宽度} 
 * @param wHeight {弹出窗体高度}
 */
function popWindow(url,titles,wWidth,wHeight){
	jQuery('body').css('overflow','hidden');
	createDIVWindow(url,titles,wWidth,wHeight);
}



/**
 * 创建DIV弹出窗体,模拟转页效果,以便保存主页数据状态
 * @param {窗体装载URL} url
 */
function createDIVWindow(url){
	var divWin = document.createElement('DIV');
    divWin.id = 'divwin';
    divWin.style.position = 'absolute';
    divWin.style.left = document.body.scrollLeft;
    divWin.style.top = document.body.scrollTop;
    divWin.style.width = "100%";
    divWin.style.height = "100%";
    divWin.style.background ='#dfe8f6';
    divWin.style.zIndex = "10000";
    var str = createIframe('div-win-iframe' , url , 'linkWindow');
    divWin.innerHTML = str;
    document.body.appendChild(divWin);
}

/**
 * @param iframeId {iframe Id}
 * @param url {装载URL} 
 * @param windowType {窗体类型} 
 */
function createIframe(iframeId , url , windowType){
	return '<iframe id='+iframeId+' frameborder="0" ' +
			'src='+getGotoUrl(url,windowType)+' scrolling="auto" ' +
				//'onload="this.height='+iframeId+'.document.body.scrollHeight"' +
					'width="100%" height="100%" ></iframe>';
}


function getBasePase(){
	//获取当前程序根目录
	var strFullPath=window.document.location.href;
	var strPath=window.document.location.pathname;
	var pos=strFullPath.indexOf(strPath);
	var prePath=strFullPath.substring(0,pos);
	var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
	return prePath + postPath;
}


function getGotoUrl(gotoUrl /*,windowType*/){
	
	if(gotoUrl.indexOf('&')!=-1){
		var url=gotoUrl.replace('&','|');
		do{
			gotoUrl = url;
			url = url.replace('&','|');
		}while(url!=gotoUrl)
	}

	var wait = encodeURI(getBasePase() + "/common/jsp/wait.jsp?gotoUrl='"+gotoUrl+"'");
	return wait;

}

/**
 * @param {装载URL} url
 * @param {转页的Iframe Id} linkIframeId
 */
function linkWindow(url ,linkIframeId){
	jQuery('body').css('overflow','hidden');
	/**
	 * update for 2008-10-16
	 */
	if(linkIframeId!=undefined){
		jQuery('#'+linkIframeId).attr('src', getGotoUrl(url,'linkWindow'));
		return;
	}
	if(url!=undefined){
		createDIVWindow(url);
	}
	/*
	if(iframeId!=undefined){
		jQuery('#'+iframeId).attr('src', getGotoUrl(url,'linkWindow'));
		return;
	}
	location = getGotoUrl(url,'linkWindow');
	*/	
}

/**
 * 关闭窗体,包括ext弹出窗体和div模拟窗体两种
 */
function closeWin(){
	parent.jQuery('body').css('overflow','auto');
	if(parent.jQuery('#divwin')!=null){
		parent.jQuery('#divwin').remove();
	}
	
}

/**
 * div模拟窗体返回
 */
function back(url ,linkIframeId){
	if(parent.jQuery('#divwin')){
		parent.jQuery('#divwin').remove();
		return;
	}
}

/**
 * 验证
 * @param validatorgroupIds {需要验证的控件组ID} 
 */
function validator(validatorgroupIds){
	if(validatorgroupIds != undefined){
		var valigroupIds = validatorgroupIds.split(",");
		for(i=0;i<valigroupIds.length;i++){
			if(!(jQuery.formValidator.pageIsValid(valigroupIds[i]))){
				return false;
			}
		}
	}else if(validatorgroupIds == undefined){
		if(!(jQuery.formValidator.pageIsValid())){
			return false;
		}
	}
	return true;
}

/**
 * 设置验证需要验证和不需要验证的控件组
 * @param unvalIds {不需要验证的控件组ID} 
 * @param valIds {需要验证的控件组ID}
 */
function unvalidator(unvalIds, valIds){
	if(unvalIds!=undefined){
		var unIds = unvalIds.split(",");
		//不校验
		for(i=0;unIds!=undefined&&i<unIds.length;i++){
			jQuery("#"+unIds[i]).unFormValidator(true);
			//jQuery("#"+unIds[i]).attr("disabled",true).unFormValidator(true);
		}
	}
	if(valIds!=undefined){
		//校验
		var Ids = valIds.split(",");
		for(i=0;Ids!=undefined&&i<unIds.length;i++){
			jQuery("#"+valIds[i]).unFormValidator(false);
			//jQuery("#"+valIds[i]).attr("disabled",false).unFormValidator(false);
		}
	}
}

/**
 * 删除多条记录确定提示
 * @param ecId {ec:table id} 
 * @param idsname {多选框name} 
 * @param func {执行删除方法名}
 */
function deleteSConfirm(url,cids,succCallBack){
	var chIds = getCheckboxValue(cids);
	//alert(chIds);
	if(chIds==''){
		alert('请选择要删除的项!'); 
		return;
	}
	//alert(chIds);
	ajaxSend(url+chIds,'确定【删除】选中项的数据吗?',succCallBack);
}

/**
 * 删除单条记录确定提示
 * @param url {url} 
 */
function deleteConfirm(url,succCallBack){
	ajaxSend(url,'确定【删除】该条数据吗?',succCallBack);
}

/**
 * ajax方式提交
 * @param url 
 */
function ajaxSend(url,msg,succCallBack){
	if(msg==undefined){
		jQueryAjax(url);
		return;
	}else{
		var c = confirm(msg);
		if(c){
			jQueryAjax(url,succCallBack);
		}
	
	}
}

function jQueryAjax(url,succCallBack){
	jQuery.ajax({
		url: url,
		ifModified:"0",
		success:function(res){
			succCallBack()
		},
		error:function(msg) {
			alert('当前操作失败!');
		}
	});
}

function ajaxMessage(msg){
	jQuery('#info').css('display','block');
	jQuery('#info').addClass('actionMessage');
	jQuery("#info").html(msg);
	//设置提示消息5秒钟后消失
	setTimeout(function(){jQuery('#info').css('display','none');return;},5000); 
}

//menu-close
function menuCloseOpen(){
	var w = Ext.getCmp('gncd');
	w.collapse(); 
}

function infoAlert(msg){
	Ext.MessageBox.alert('消息', msg);
}

/**
 * 获取多个checkbox的值
 * @param {} checkName
 */
function getCheckboxValue(checkName){
	var checkValue = "";
	jQuery("input[name='"+checkName+"'][checked]").each(function(){ 
		//alert(jQuery(this).val());
		checkValue += jQuery(this).val()+",";
    });
    return checkValue;
}
/**
 * 获取多个input的值
 * @param {} inputName
 */
function getInputValue(inputName){
	var inputValue = "";
	jQuery("input[@name="+inputName+"]").each(function(){ 
		inputValue += jQuery(this).val()+",";
    })
    return inputValue;
}

/**
 * 获取select已选择的文本或者值
 * @param {通过id或name查找} pro
 * @param {id或name查找} selectName
 * @param {text或value} type
 */
function getSelectVal(pro,selectName,type){
	var selectValue = "";
	jQuery("select[@"+pro+"="+selectName+"] option[@selected]").each(function(){ 
		if(type=='text'){
			selectValue += jQuery(this).text();
		}else if(type=='value'){
			selectValue += jQuery(this).val();
		}
    });
    return selectValue;
}



function creatCodeBarConfirm(url,succCallBack){
	ajaxSend(url,'确定【删除】该条数据吗?',succCallBack);
}

function mcheckAll(thisobj,checkName){
  	$("#"+checkName+" input").each(function(){
  		$(this).attr("checked",thisobj.checked);
  	});
}
